package com.peng.leetcode.other;

/**
 * CountSubstrings
 *
 * @author: lupeng6
 * @create: 2020/12/21 21:29
 */
public class CountSubstrings {

    public static void main(String[] args) {
        String s = "aaa";
        System.out.println(new Solution().countSubstrings(s));
    }

    static class Solution {
        public int countSubstrings(String s) {
            int count = 0;
            for (int i = 0; i < s.length(); i++) {
                int offset = 0;
                while ((i - offset) >= 0 && (i + offset) < s.length()) {
                    if (s.charAt(i - offset) != s.charAt(i + offset)) {
                        break;
                    }
                    offset++;
                    count++;
                }
            }
            return count;
        }
    }
}
